Skip to content

fix: handle UnicodeDecodeError race condition in copaw-worker#791

Open
nillikechatchat wants to merge 4 commits into
agentscope-ai:mainfrom
nillikechatchat:fix/copaw-worker-unicode-decode-race
Open

fix: handle UnicodeDecodeError race condition in copaw-worker#791
nillikechatchat wants to merge 4 commits into
agentscope-ai:mainfrom
nillikechatchat:fix/copaw-worker-unicode-decode-race

Conversation

@nillikechatchat

Copy link
Copy Markdown
Contributor

Summary

Fix for Issue #728: UnicodeDecodeError race condition in copaw-worker.

Problem

When mc mirror completes file synchronization, there is a race condition where file reads can occur before the file is fully written to disk. This causes UnicodeDecodeError when reading multi-byte UTF-8 characters at the end of files.

Solution

Added _read_text_with_retry() helper function in both worker.py and sync.py that:

  • Catches UnicodeDecodeError during file reads
  • Retries up to 5 times with 100ms delay between attempts
  • Logs debug info on retries, warning on final failure

Files Changed

  • copaw/src/copaw_worker/worker.py - Added retry logic for SOUL.md, AGENTS.md, HEARTBEAT.md reads
  • copaw/src/copaw_worker/sync.py - Added retry logic for team_id.txt and team_leader.txt reads

Fixes #728

nillikechatchat and others added 2 commits May 10, 2026 04:26
…codeDecodeError race

This fixes the race condition between mc mirror reporting completion and the file
being fully written to disk. The race can cause partial reads of multi-byte UTF-8
characters at the end of the file, resulting in UnicodeDecodeError crashes during
worker startup.

Fixes: agentscope-ai#728

Changes:
- Add _read_text_with_retry() helper function in both worker.py and sync.py
- The function retries up to 5 times with 100ms delay on UnicodeDecodeError
- Apply retry mechanism to all read_text() calls for AGENTS.md, SOUL.md, and openclaw.json
- Add debug logging for retry attempts to improve observability
@github-actions

github-actions Bot commented May 11, 2026

Copy link
Copy Markdown
Contributor

📊 CI Metrics Report

Summary

Metric Current Baseline Change
LLM Calls 74 86 -12 ↓ -14.0%
Input Tokens 2746168 3825223 -1079055 ↓ -28.2%
Output Tokens 18327 19253 -926 ↓ -4.8%
Total Tokens 2764495 3844476 -1079981 ↓ -28.1%

By Role

Role Metric Current Baseline Change
🧠 Manager LLM Calls 66 75 -9 ↓ -12.0%
Input Tokens 2565560 3572217 -1006657 ↓ -28.2%
Output Tokens 16398 16994 -596 ↓ -3.5%
Total Tokens 2581958 3589211 -1007253 ↓ -28.1%
🔧 Workers LLM Calls 8 11 -3 ↓ -27.3%
Input Tokens 180608 253006 -72398 ↓ -28.6%
Output Tokens 1929 2259 -330 ↓ -14.6%
Total Tokens 182537 255265 -72728 ↓ -28.5%

Per-Test Breakdown

Test Mgr Calls Wkr Calls Δ Calls Mgr In Wkr In Mgr Out Wkr Out Δ Tokens Trend
02-create-worker 10 0 -7 ↓ -41.2% 296915 0 2673 0 -236983 ↓ -44.2% ✅ improved
03-assign-task 10 3 -2 ↓ -13.3% 362625 70522 1707 366 -148671 ↓ -25.5% ✅ improved
04-human-intervene 17 0 +4 ↑ +30.8% 597735 0 3128 0 +57245 ↑ +10.5% ⚠️ regressed
05-heartbeat 8 0 +1 ↑ +14.3% 325595 0 1983 0 -14785 ↓ -4.3% ⚠️ regressed
06-multi-worker 21 5 -8 ↓ -23.5% 982690 110086 6907 1563 -736787 ↓ -40.1% ✅ improved

Trends

3 test(s) improved (fewer LLM calls)
⚠️ 2 test(s) regressed (more LLM calls)


Generated by HiClaw CI on 2026-05-21 06:16:06 UTC


📦 Download debug logs & test artifacts

@github-actions

github-actions Bot commented May 11, 2026

Copy link
Copy Markdown
Contributor

❌ Integration Tests Failed (llm-interaction / mgr=copaw / wk=copaw)

Commit: 20e4f9d
Workflow run: #1018

Test Results
No test output captured.
Debug Log (tail)
No debug logs available.

📦 Download full debug logs & test artifacts

@github-actions

Copy link
Copy Markdown
Contributor

❌ Integration Tests Failed (llm-interaction-2 / mgr=copaw / wk=copaw)

Commit: 1f4341f
Workflow run: #1013

Test Results
No test output captured.
Debug Log (tail)
No debug logs available.

📦 Download full debug logs & test artifacts

@github-actions

Copy link
Copy Markdown
Contributor

❌ Integration Tests Failed (llm-interaction / mgr=copaw / wk=hermes)

Commit: 1f4341f
Workflow run: #1013

Test Results
No test output captured.
Debug Log (tail)
No debug logs available.

📦 Download full debug logs & test artifacts

@flystar32 flystar32 self-requested a review May 11, 2026 08:09

@flystar32 flystar32 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@shiyiyue1102

Copy link
Copy Markdown
Collaborator

Thanks for the update. This PR currently has conflicts with the target branch, so it cannot be reviewed or merged cleanly yet. Please rebase or merge the target branch and resolve the conflicts, then update the PR.


感谢更新。这个 PR 当前与目标分支存在冲突,暂时无法干净地 review 或合并。请先 rebase 或 merge 目标分支并解决冲突,然后更新 PR。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] copaw-worker 启动时 UnicodeDecodeError 读取 SOUL.md/AGENTS.md —— mc mirror 与 read_text 之间的文件稳定性 race

3 participants